package com.peng.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.peng.mapper.DeptMapper;
import com.peng.pojo.Dept;
import com.peng.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class DeptController {

    @Autowired
    private DeptService service;


    @GetMapping("/dept/id/{id}")
    @HystrixCommand(fallbackMethod = "hystrixId")
    public Dept queryId(@PathVariable("id") long id){

        Dept dept= service.queryId(id);
        if (dept==null){
            throw new RuntimeException();
        }
        return dept;
    }

    public Dept hystrixId(@PathVariable("id") long id){
        return new Dept().setDeptno(id).setDname("id->"+id+"不存在");
    }

}
